var a = getApp(), t = require("../../provider/dataApi.js"), e = require("../../provider/pipe.js");

Page({
    data: {
        isloading: !0,
        isCanAnswer: !1,
        statusBarHeight: "",
        titleBarHeight: "",
        banner: [],
        notice: [],
        last_id: 0,
        total: 0,
        banner_height: "",
        is_can: "",
        adInfo: {},
        ad_have: 2,
        icons: {},
        countdown: {},
        countdownTime: 0,
        count_day: {},
        rate: {},
        activationShow: !1,
        setCDKey: ""
    },
    registerFormSubmit: function(a) {
        wx.getStorageSync("uid") && t.getFormid({
            uid: wx.getStorageSync("uid"),
            formid: a.detail.formId
        }).then(function(a) {}).catch(function(a) {});
    },
    onSequencePractice() {
      console.log('点击了顺序练习');
      // 这里可以添加你的业务逻辑，比如跳转页面等
    },
    onLoad: function(a) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        });
    },
    goBanner: function(t) {
        wx.getStorageSync("uid") || wx.navigateTo({
            url: "../login/login"
        }), "1" == (t = a.globalData.item = t.currentTarget.dataset.item).type ? ("1" == (t = t.link) && wx.navigateTo({
            url: "/pages/my-medal/my-medal"
        }), "2" == t && wx.switchTab({
            url: "/pages/error/error"
        }), "3" == t && wx.switchTab({
            url: "/pages/ranking/ranking"
        }), "4" == t && wx.switchTab({
            url: "/pages/mine/mine"
        }), "5" == t && wx.navigateTo({
            url: "/pages/exam-desc/exam-desc"
        }), "6" == t && wx.navigateTo({
            url: "/pages/integral-mall/integral-mall"
        }), "7" == t && wx.navigateTo({
            url: "/pages/vip/vip"
        })) : "2" == t.type ? wx.navigateTo({
            url: "../webView/webView"
        }) : "3" == t.type && (a.globalData.id = t.link, wx.navigateTo({
            url: "/pages/article-info/article-info?type=article"
        }));
    },
    goLx: function() {
       /*  var t = this.data.isCanAnswer;
        a.globalData.op = "sequence", wx.getStorageSync("uid") ? t ? (a.globalData.id = "", 
        wx.navigateTo({
            //url: "/pages/quesBankType/quesBankType"
            url: "/pages/keyi/keyi"
        })) : this.testInfo() : wx.navigateTo({
            url: "../login/login"
        }); */
        wx.navigateBack()
    },
    goLx2:function(){
      wx.navigateTo({
        url: "/pages/practice/practice"
      })
    },
    goExam: function() {
        var a = this.data.isCanAnswer;
        wx.getStorageSync("uid") ? a ? wx.navigateTo({
            url: "../exam-desc/exam-desc"
        }) : this.testInfo() : wx.navigateTo({
            url: "../login/login"
        });
    },
    bindWechat: function() {
        wx.showModal({
            title: "绑定微信",
            content: "需要绑定微信才能进行下一步操作,点击确定去绑定",
            showCancel: !0,
            confirmText: "确定",
            success: function(a) {
                console.log(a), a.confirm && wx.navigateTo({
                    url: "../bindWechat/bindWechat"
                });
            }
        });
    },
    testInfo: function() {
        wx.showModal({
            title: "完善信息",
            content: "答题前需要完善姓名和手机号信息",
            showCancel: !0,
            confirmText: "去完善",
            success: function(a) {
                console.log(a), a.confirm && wx.navigateTo({
                    url: "../my-info/my-info"
                });
            }
        });
    },
    golianX: function(t) {
        t = t.currentTarget.dataset.item;
        var e = Number(t.doid), n = t.types, o = t.title, i = this.data.isCanAnswer;
        if (wx.getStorageSync("uid")) if (i) if (console.log(t), a.globalData.id = "", 2 == n) 0 == t.is_can ? wx.navigateTo({
            url: "/pages/classification/classification?type=1&id=" + t.gpid
        }) : (a.globalData.op = "special", a.globalData.id = t.library_id, wx.navigateTo({
            url: "/pages/practice/practice"
        })); else switch (a.globalData.title = o, e) {
          case 1:
            wx.navigateTo({
                url: "../classification/classification"
            });
            break;

          case 2:
            wx.navigateTo({
                url: "/pages/quesBankType/quesBankType?type=1"
            });
            break;

          case 3:
            a.globalData.op = "randoms", wx.navigateTo({
                url: "/pages/quesBankType/quesBankType"
            });
            break;

          case 4:
            a.globalData.op = "collection_question", wx.navigateTo({
                url: "../practice/practice"
            });
            break;

          case 5:
            wx.switchTab({
                url: "../error/error"
            });
            break;

          case 6:
            a.globalData.op = "notdone", wx.navigateTo({
                url: "/pages/quesBankType/quesBankType"
            });
            break;

          case 7:
            a.globalData.type = 1, wx.navigateTo({
                url: "../knowledgePoints/knowledgePoints"
            });
            break;

          case 8:
            a.globalData.type = 2, wx.navigateTo({
                url: "../knowledgePoints/knowledgePoints"
            });
        } else this.testInfo(); else wx.navigateTo({
            url: "../login/login"
        });
    },
    getCode: function() {
        wx.getStorageSync("uid") ? this.setData({
            activationShow: !0
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    onClose: function() {
        this.setData({
            activationShow: !1
        });
    },
    onChange: function(a) {
        this.setData({
            setCDKey: a.detail
        });
    },
    onConfirm: function() {
        var a = this;
        this.data.setCDKey ? t.setCDKey({
            uid: wx.getStorageSync("uid"),
            code: this.data.setCDKey
        }).then(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: t.message
            }), a.setData({
                setCDKey: ""
            });
        }).catch(function(a) {
            console.log(a), wx.showToast({
                icon: "none",
                title: "该激活码不可用"
            });
        }) : wx.showToast({
            icon: "none",
            title: "请输入激活码"
        });
    },
    queryAd: function() {
        var a = this;
        t.advert({
            op: "home"
        }).then(function(t) {
            console.log(t), a.setData({
                adInfo: t.data.info,
                ad_have: t.data.ad_have
            });
        }).catch(function(a) {
            console.log(a);
        });
    },
    onShow: function() {
        this.getuserinfo(), this.totalqNum(), this.indexData(), this.queryAd(), this.versionUpdating();
    },
    versionUpdating: function() {
        if (wx.canIUse("getUpdateManager")) {
            var a = wx.getUpdateManager();
            a.onCheckForUpdate(function(t) {
                console.log("onCheckForUpdate====", t), t.hasUpdate && (console.log("res.hasUpdate===="), 
                a.onUpdateReady(function() {
                    wx.showModal({
                        title: "更新提示",
                        content: "新版本已经准备好，是否重启应用？",
                        showCancel: !1,
                        confirmText: "确认",
                        success: function(t) {
                            console.log("success====", t), t.confirm && (a.applyUpdate(), wx.clearStorageSync());
                        }
                    });
                }), a.onUpdateFailed(function() {
                    wx.showModal({
                        title: "已经有新版本了哟~",
                        content: "新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~"
                    });
                }));
            });
        }
    },
    goNotice: function(t) {
        wx.getStorageSync("uid") || wx.navigateTo({
            url: "../login/login"
        }), a.globalData.id = t.currentTarget.dataset.id, wx.navigateTo({
            url: "../article-info/article-info?type=notice"
        });
    },
    indexData: function() {
        var a = this, e = 0;
        wx.getStorageSync("uid") && (e = wx.getStorageSync("uid")), t.indexData({
            uid: e
        }).then(function(t) {
            console.log(t), a.setData({
                banner: t.data.banner,
                notice: t.data.notice,
                banner_height: t.data.banner_height,
                share_title: t.data.share_title,
                icons: t.data.icons,
                countdown: t.data.countdown,
                count_day: t.data.count_day,
                rate: t.data.rate,
                isloading: !1
            }), console.log(t.data.countdown), a.djsFun(t.data.countdown.countdowntime);
        }).catch(function(a) {
            console.log(a);
        });
    },
    djsFun: function(a) {
        var t = 0;
        0 < 1e3 * a - new Date().getTime() && (t = e.formatDateDayTimehour(1e3 * a)), this.setData({
            countdownTime: t
        });
    },
    totalqNum: function() {
        var a = this;
        t.totalqNum({
            uid: wx.getStorageSync("uid")
        }).then(function(t) {
            console.log(t), a.setData({
                last_id: Number(t.data.last_id),
                total: t.data.total,
                is_can: t.data.is_can
            });
        }).catch(function(a) {
            console.log(a);
        });
    },
    getuserinfo: function() {
        var a = this;
        t.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(t) {
            console.log(t);
            var e = t.data.info;
            wx.setStorageSync("userinfo", e), wx.setStorageSync("http", t.data.http);
            var n = !1;
            1 == e.is_ok && (n = !0), a.setData({
                isCanAnswer: n,
                isShowKey: t.data.app_id
            });
        }).catch(function(a) {
            console.log(a);
        });
    },
    onShareAppMessage: function() {}
});